﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Collections.Specialized;
using System.Reflection;

namespace SoftballStats
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["SeasonID"] != null)
                {
                    SoftballStats_BL.Season selectedSeason = SoftballStats_BL.Season.GetSeasonByID(Request.QueryString["SeasonID"]);
                    if (selectedSeason.Year != -1)
                    {
                        lblCurrentSeason.Text = selectedSeason.Description + " " + selectedSeason.Year;
                        Session["Season"] = selectedSeason;

                        /* remove SeasonID from QueryString */
                        PropertyInfo isReadOnly = typeof(NameValueCollection).GetProperty("IsReadOnly", BindingFlags.Instance | BindingFlags.NonPublic);
                        isReadOnly.SetValue(this.Request.QueryString, false, null);
                        this.Request.QueryString.Remove("SeasonID");
                        isReadOnly.SetValue(this.Request.QueryString, true, null);
                    }
                }
                else
                {
                    if (Session["Season"] == null)
                    {
                        SoftballStats_BL.Season currentSeason = SoftballStats_BL.Season.GetCurrentSeason();
                        if (currentSeason.Year != -1)
                        {
                            lblCurrentSeason.Text = currentSeason.Description + " " + currentSeason.Year;
                            Session["Season"] = currentSeason;
                        }
                    }
                    else
                    {
                        SoftballStats_BL.Season currentSeason = (SoftballStats_BL.Season)Session["Season"];
                        lblCurrentSeason.Text = currentSeason.Description + " " + currentSeason.Year;
                    }
                }

                GetHotPlayer();
            }
        }

        private void GetHotPlayer()
        {
            //Get Player via method in Player class

            imgHot.ImageUrl = SoftballStats_BL.Player.GetPlayerImage("Christian Cox");
            //imgHot.Height = 350;
            //imgHot.Width = 350;
            lblHotName.Text = "Christian Cox";
            lblHotNumber.Text = "#16";
            lblHotPosition.Text = "1B";
            lblHotStats.Text = "11/13, .846 BA, .867 OBP, .923 SLG, 1.790 OPS, 7 RBI, 12 TB";
        }
    }
}
